package com.yx.frame.builder.xml;

import com.yx.frame.builder.validate.ServiceBuilderConfigManager;
import com.yx.frame.builder.validate.Validator;

public class MethodParmXml {

	int id;
	String name = "";
	String type = "";
	String isMutilist = "false";
	String sqlIndex = "";
	String validator = "";
	String comment = "";

	public MethodParmXml(int id, String name, String type, String isMutilist,String sqlIndex,String validator, String comment) {
		this.id = id;
		this.name = name;
		this.type = type;
		this.isMutilist = isMutilist;
		this.sqlIndex=sqlIndex;
		this.validator = validator;
		this.comment = comment;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public String getIsMutilist() {
		return isMutilist;
	}

	public String getSqlIndex() {
		return sqlIndex;
	}
	public String getValidator() {
		return validator;
	}

	public String getComment() {
		return comment;
	}

	public Validator[] getValidators() throws Exception {
		if ("".equals(this.getValidator()))
			return new Validator[0];
		String[] validatorNames = this.getValidator().split(",");
		Validator[] validators = new Validator[validatorNames.length];
		for (int i = 0; i < validatorNames.length; i++) {
			validators[i] = ServiceBuilderConfigManager.getInstance().getValidator(
					validatorNames[i]);
			if (validators[i] == null) {
				throw new Exception("没有参数校验" + validatorNames[i]);
			}
		}
		return validators;
	}

	public boolean isMutilistType() {
		if ("true".equals(isMutilist)) {
			return true;
		} else {
			return false;
		}
	}

	public StringBuffer toXml() {
		StringBuffer xml = new StringBuffer();
		xml.append("			<Parm id=\"" + this.getId() + "\" name=\""
				+ this.getName() + "\" type=\"" + this.getType()
				+ "\" isMutilist=\"" + this.getIsMutilist() + "\" sqlIndex=\""
				+ this.getSqlIndex() + "\" validator=\"" + this.getValidator() + "\" comment=\""
				+ this.getComment() + "\" />\r\n");
		return xml;
	}
}
